<template>
    <div class="home">
        <div v-html="tableau"></div>
    </div>
</template>
   
<script>
import axios from 'axios'
import XLSX from 'xlsx'

export default {
    name: 'excel',
    data() {
        return {
            tableau: null,
        }
    },
    mounted() {
        axios.get('http://192.168.101.14:19000/public/test.xlsx', {
            responseType: "arraybuffer", // 设置响应体类型为arraybuffer
        }).then(({ data }) => {
            let workbook = XLSX.read(new Uint8Array(data), { type: "array" }); // 解析数据
            var worksheet = workbook.Sheets[workbook.SheetNames[0]]; // workbook.SheetNames 下存的是该文件每个工作表名字,这里取出第一个工作表
            this.tableau = XLSX.utils.sheet_to_html(worksheet); // 渲染
        })
    }
};
</script>